package com.ruoyi.web.controller.fund;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.cost.service.IHouseCostTService;
import com.ruoyi.costQuery.domain.HouseCostT;
import com.ruoyi.costQuery.service.IHouseCostQueryTService;
import com.ruoyi.data.MD5;
import com.ruoyi.data.NumberData;
import com.ruoyi.door.domain.HouseDoorT;
import com.ruoyi.purpose.service.IHousePurposeTService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 户管理Controller
 * 
 * @author lijie
 * @date 2023-04-20
 */
@RestController
@RequestMapping("/fund/cost")
public class HouseCostTController extends BaseController
{
    @Autowired
    private IHouseCostTService houseCostTService;
    private IHouseCostQueryTService houseCostQueryTService;

    @Autowired
    private IHousePurposeTService housePurposeTService;
    /**
     * 查询户管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseDoorT houseDoorT)
    {
        startPage();
        List<HouseDoorT> list = houseCostTService.selectHouseDoorTList(houseDoorT);
        for(HouseDoorT houseDoorVO:list){
            houseDoorVO.setPapersCode(MD5.md5(houseDoorVO.getPapersCode()));
        }
        if(getDataTableSumJudge(list)){
            HouseDoorT houseDoorVO = houseCostTService.selectHouseDoorSum(houseDoorT);
            houseDoorVO.setAreaName("合计");
            list.add(houseDoorVO);
        }
        return getDataTable(list);
    }

    /**
     * 导出户管理列表
     */
    @Log(title = "户管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseDoorT houseDoorT)
    {
        List<HouseDoorT> list = houseCostTService.selectHouseDoorTList(houseDoorT);
        ExcelUtil<HouseDoorT> util = new ExcelUtil<HouseDoorT>(HouseDoorT.class);
        util.exportExcel(response, list, "户管理数据");
    }

    /**
     * 获取户管理详细信息
     */
    @GetMapping(value = "/{doorId}")
    public AjaxResult getInfo(@PathVariable("doorId") Long doorId)
    {
        HouseDoorT houseDoorVO = houseCostTService.selectHouseDoorTByDoorId(doorId);
        houseDoorVO.setPapersCode(MD5.md5(houseDoorVO.getPapersCode()));
        return AjaxResult.success(houseDoorVO);
    }
    /*缴费通知书*/
    @GetMapping(value = "getNote/{doorId}")
    public AjaxResult getNote(@PathVariable("doorId") Long doorId)
    {
        HouseDoorT houseDoorVO=houseCostTService.selectHouseDoorTByDoorId(doorId);
        houseDoorVO.setBudgetMoneyDX(NumberData.makeUpperCaseSum(String.valueOf(houseDoorVO.getBudgetMoney())));
        return AjaxResult.success(houseDoorVO);
    }

    /**
     * 缴费
     */
    @Log(title = "缴费管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult insertCost(@RequestBody HouseDoorT houseDoorT)
    {
        houseDoorT.setCreater(getUsername());
        int costId = houseCostTService.updateHouseDoorT(houseDoorT);
        HouseCostT houseCostVO = new HouseCostT();
        houseCostVO.setCostId(Long.valueOf(costId));
        return AjaxResult.success(houseCostVO);
    }


}
